package course13;

public class Mistake4 {

    public static void testOne(int x)throws ArrayIndexOutOfBoundsException, ArithmeticException {

        System.out.println(x);

        if (x == 0) {
            System.out.println("没有异常");
        }

        //数组越界异常
        else if (x == 1) {
            throw new ArithmeticException("数组越界异常");
           // int[] a = new int[3];
           // a[3] = 5;          这两个是在干嘛？

        }

        //算数异常
        else if (x == 2) {
            throw new ArithmeticException("算数异常，两数相除，除数不能为0" );
           // int i = 0;
           // int j = 5 / 0;     这两个是在干嘛？

        }
    }

    //作业：定义一个main函数，引用testOne方法，然后捕获testOne方法中定义的两个异常

    public static void main(String[] args) {
        try {
            testOne(2);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println(e.getMessage());
        } catch (ArithmeticException e) {
            System.out.println(e.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }
}
